package hczc.longcai.com.hccrowdfunding.home.first_index.fragments;


import android.content.Intent;
import android.os.Bundle;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;

import hczc.longcai.com.hccrowdfunding.R;
import hczc.longcai.com.hccrowdfunding.application.BaseApplication;
import hczc.longcai.com.hccrowdfunding.home.HomeActivity;
import hczc.longcai.com.hccrowdfunding.home.second_invest.SecondFragment;

/**
 *
 *  首页标签的Fragment
 */
public class LabelFragment extends Fragment implements View.OnClickListener, View.OnTouchListener {


    /**
     * 国际众筹
     */
    private RelativeLayout internation;
    /**
     * 股权众筹
     */
    private RelativeLayout stock;
    /**
     * 债权众筹
     */
    private RelativeLayout bond;
    /**
     * 抵押众筹
     */
    private RelativeLayout pledge;
    /**
     * 艺术众筹
     */
    private RelativeLayout art;
    /**
     * 公益众筹
     */
    private RelativeLayout publiccrowd;
    /**
     * 其他众筹
     */
    private RelativeLayout elsecrowd;
    /**
     * 全部众筹
     */
    private RelativeLayout all;

    public LabelFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_label, container, false);
        BaseApplication.scaleScreenHelper.loadView(((ViewGroup) view));
        initViews(view);
        return view;
    }

    private void initViews(View view) {
        internation = ((RelativeLayout) view.findViewById(R.id.index_label_international));
        internation.setOnClickListener(this);
        internation.setOnTouchListener(this);
        stock = ((RelativeLayout) view.findViewById(R.id.index_label_stock));
        stock.setOnClickListener(this);
        stock.setOnTouchListener(this);
        bond = ((RelativeLayout) view.findViewById(R.id.index_label_bond));
        bond.setOnClickListener(this);
        bond.setOnTouchListener(this);
        pledge = ((RelativeLayout) view.findViewById(R.id.index_label_pledge));
        pledge.setOnClickListener(this);
        pledge.setOnTouchListener(this);
        art = ((RelativeLayout) view.findViewById(R.id.index_label_art));
        art.setOnClickListener(this);
        art.setOnTouchListener(this);
        publiccrowd = ((RelativeLayout) view.findViewById(R.id.index_label_public));
        publiccrowd.setOnClickListener(this);
        publiccrowd.setOnTouchListener(this);
        elsecrowd = ((RelativeLayout) view.findViewById(R.id.index_label_else));
        elsecrowd.setOnClickListener(this);
        elsecrowd.setOnTouchListener(this);
        all = ((RelativeLayout) view.findViewById(R.id.index_label_all));
        all.setOnClickListener(this);
        all.setOnTouchListener(this);
    }


    @Override
    public void onClick(View view) {
        Intent intent = new Intent();
        intent.setAction("change");
        Bundle bundle = new Bundle();
        int lable = SecondFragment.LABLE_ALL;

        int id = view.getId();
        switch (id){
            /**
             * 国际众筹
             */
            case R.id.index_label_international:
                lable = SecondFragment.LABLE_INTERNATIONAL;

                break;
            /**
             * 股权众筹
             */
            case R.id.index_label_stock:
                lable = SecondFragment.LABLE_STOCK;
                break;
            /**
             * 债券众筹
             */
            case R.id.index_label_bond:
                lable = SecondFragment.LABLE_BOND;
                break;
            /**
             * 抵押众筹
             */
            case R.id.index_label_pledge:
                lable = SecondFragment.LABLE_PLEDGE;
                break;
            /**
             * 艺术众筹
             */
            case R.id.index_label_art:
                lable = SecondFragment.LABLE_ART;
                break;
            /**
             * 公益众筹
             */
            case R.id.index_label_public:
                lable = SecondFragment.LABLE_PUBLIC;
                break;
            /**
             * 其他众筹
             */
            case R.id.index_label_else:
                lable = SecondFragment.LABLE_ELSE;
                break;
            /**
             * 全部众筹
             */
            case R.id.index_label_all:

                break;

        }
        bundle.putInt("lable",lable);
        intent.putExtras(bundle);
        getActivity().sendBroadcast(intent);
    }


    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        view.setPressed(true);
        return false;
    }
}
